# -*- coding: utf-8 -*-

from django.db import models
from konto.models import userModel

class Modules(models.Model):
    """ Możliwe widgety """
    name = models.CharField('Nazwa', max_length=30, unique=True)
    module = models.CharField(u'Moduł', max_length=30, unique=True)

    class Meta:
        verbose_name = u"Moduł"
        verbose_name_plural = u"Moduły"

    def __unicode__(self):
        return self.name

class Widget(models.Model):
    """ Obiekt widgeta """
    wid = models.ForeignKey(Modules, name=u'Widget ID', related_name='widget')
    owner = models.ForeignKey(userModel, name=u"Właściciel", related_name='widgety')
    hidden = models.BooleanField(u'Schowany', default=False)
    shade = models.BooleanField(u'Zwinięty', default=False)
    elements = models.IntegerField(u'Ilość elementów', default=5)
    col = models.IntegerField(u'Kolumna', default=1)
    order = models.IntegerField(u'Kolejność', default=1)
	
    class Meta:
        verbose_name = u"Widget"
        verbose_name_plural = u"Widgety"
        ordering = ['-col', '-order']

    def __unicode__(self):
        return self.wid.name

class Note(models.Model):
    """ Notatka do widgeta 'notatki' """
    widget = models.ForeignKey(Widget, name=u'Widget', related_name='notatki')
    tresc = models.TextField(u'Treść', max_length=300)
    data_utworzenia = models.DateTimeField(u'Data utworzenia', auto_now=True)
	
    class Meta:
        verbose_name = u'Notatka'
        verbose_name_plural = u'Notatki'
        ordering = ['-data_utworzenia']
	
    def __unicode__(self):
        if len(self.tresc) > 20:
            return self.tresc[:20] + '...'
        else:
            return self.tresc
